package com.stars.empoly.adapter

import android.graphics.Color
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.activity.ReceivedDetailsActivity
import com.stars.empoly.databinding.ItemHomeListBinding
import com.stars.empoly.model.OrderList
import com.stars.empoly.vmodel.HomeListVModel
import com.trailer.base.base.BAdapter
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

class HomeListAdapter(var vm: HomeListVModel) :
    BAdapter<OrderList, BaseDataBindingHolder<ItemHomeListBinding>>(R.layout.item_home_list) {
    override fun convert(holder: BaseDataBindingHolder<ItemHomeListBinding>, item: OrderList) {
        holder.dataBinding?.item = item
        holder.dataBinding?.vm = vm
        //设置状态
        if (item.status == -2 || item.status == -1 || item.status == 0 || item.status == 3 || (item.status == 1 && item.technicianStatus == 0) ||
            item.technicianStatus == 5
        ) {

            if(item.status == -2 ){
                holder.dataBinding?.tvStatus?.text="已拒单"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#F14351"))
            }

            if(item.status == -1 ){
                holder.dataBinding?.tvStatus?.text="已取消"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#F14351"))
            }
            if(item.status == 0 ){
                holder.dataBinding?.tvStatus?.text="待支付"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#F14351"))
            }

            if(item.status == 3 ){
                holder.dataBinding?.tvStatus?.text="已完成"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#08CDB2"))
            }
            if((item.status == 1 && item.technicianStatus == 0)){

                holder.dataBinding?.tvStatus?.text="待接单"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#FFAF00"))
            }
            if( item.technicianStatus == 5){

                holder.dataBinding?.tvStatus?.text="已完成"
                holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#08CDB2"))
            }


        } else {

            holder.dataBinding?.tvStatus?.text="进行中"
            holder.dataBinding?.tvStatus?.setTextColor(Color.parseColor("#2BA3FF"))
        }


        //设置服务列表
        var adapter = ServerOrderAdapter()
        holder.dataBinding?.recyclerServer?.adapter = adapter
        adapter.addData(item.serviceInfo)

        adapter.setOnItemClickListener { adapter, view, position ->
            UiSwitch.bundle(
                context(),
                ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
            )

        }

        holder.dataBinding?.ll?.onClick {
            //查看详情

            UiSwitch.bundle(
                context(),
                ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
            )


//            if(item.status==-2||item.status==-1||item.status==0||item.status==3||(item.status==1&&item.technicianStatus==0)||
//                    item.technicianStatus==5){
//                //未接单的详情
//                UiSwitch.bundle(
//                    context(),
//                    ReceivedDetailsActivity::class.java, B().putString("id", item.id).ok()
//                )
//
//            }else {
//
//                //已接单的详情
//                UiSwitch.bundle(
//                    context(),
//                    OrderDetailsActivity::class.java, B().putString("id", item.id).ok()
//                )
//            }

        }

    }
}
